package com.trace.app.controller;


import com.trace.app.entity.Order;
import com.trace.app.entity.ResponseResult;
import com.trace.app.service.OrderService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Order)表控制层
 *
 * @author lionkliu
 * @since 2024-04-22 18:18:44
 */
@RestController
@RequestMapping("order")
public class OrderController {

    @Resource
    private OrderService orderService;

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return orderService.selectPage(pageNum, pageSize);
    }

    @GetMapping("/list")
    public ResponseResult list() {
        return ResponseResult.okResult(orderService.list());
    }

    @GetMapping("{id}")
    public ResponseResult selectOne(@PathVariable Integer id) {
        return orderService.selectOne(id);
    }

    @GetMapping("/user/{userId}")
    public ResponseResult getOrderByUserId(@PathVariable Integer userId) {
        return orderService.getOrderByUserId(userId);
    }


    @PostMapping
    public ResponseResult insert(@RequestBody Order order) {
        return orderService.insertOne(order);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Order order) {
        return orderService.updateOne(order);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Integer id) {
        return orderService.deleteById(id);
    }

}
